<?php header("Content-Type: text/html; charset=utf-8");?>
<style>

.load{float:left;width:90%;padding-left:40px;margin-bottom:10px;display:none;}
.tip{float:left;width:90%;padding-left:25px;margin-bottom:10px;}
.load a{color:blue;}
.load a:hover{text-decoration:underline;}
.jspContainer{overflow:hidden}
.process{float:left;width:90%;padding-left:40px;margin-bottom:10px;display:none}
.process a{color:blue}
#allupdatalog{float:left;width:80%;margin-top:20px;}


</style>
<div class="right_side_scollbar" style="min-height:550px;padding-top:20px; overflow:hidden" >
	<div class="right_side_operate_area">
		
		<div class="tip" style="color:red; font-size:13px;">
		注：在数据同步时，请不要关闭窗口，否则会导致数据丢失。	
		</div>
		<div class="clear"></div>
		</div>
	<div class="tip" style="margin-top:30px;padding-left:40px;">
	点击按钮，我们将同步大科园，科创园的数据到常熟领军人才数据库中。
	</div>
	<div class="form_add_submit left" style="padding-left:40px;">
	<input id="updata" type="submit" style="border:0;margin-top:20px;" value="同步数据" />
	<input id="showlog" type="submit" style="border:0;margin-top:20px;margin-left:20px;" value="同步日志" />
	</div>

		
	<div class="load" >
	<?php	echo $html->image('loading.gif'); ?>
	</div>
	<div class="load" >
		<?php echo "正在更新数据 ,请勿关闭窗口...";	?>
	</div>
	<div class="load" >
		<?php echo "正在删除原有数据...";	?>
	</div>
	<div id="loadmsg">
		<div  id="step1" class="process">删除大科园，科创园数据成功</div>
		<div  id="step2" class="process">开始下载大科园最新数据...</div>
		<div  id="step3" class="process">下载大科园数据成功</div>
		<div  id="step4" class="process">开始下载科创园最新数据...</div>
		<div  id="step5" class="process">下载科创园数据成功</div>
		<div  id="step6" class="process">数据更新成功，点击<a href='http://ljrctest.sturgeon.mopaas.com/companys/index'>跳转至首页</a></div>
	</div>
	<div id="allupdatalog" style="display:none;">
		<table  border="1" cellpadding="3" cellspacing="0" style="width: 600px;margin-left:40px;">
			<tr width=600>
				<td width =60>序号</td>
				<td width =220>用户</td>
				<td width =280>同步时间</td>
				<td width =320>同步大科园数据(个)</td>
				<td width =320>同步科创园数据(个)</td>
			</tr>
			
		<?php
			$fp=fopen("../../doc/UpdateLog.txt",'r');
			$str="";
			while (!feof($fp)){
				$str.= fgets($fp);
			}
			$logpics = explode("#",$str);
			array_pop($logpics);
			$logpic = array();
			
			for($i=0;$i<count($logpics);$i++){
				$logpic[] = explode("," ,$logpics[$i]);
			}

			$k = 0;
			foreach($logpic as $line){
				echo "<tr width=600>";
				echo "<td align=center width =60>".$k."</td>";
				echo "<td align=center width =220 >".$line[0]."</td>";
				echo "<td align=center width =280>".$line[1]."</td>";
				echo "<td align=center width =320>".$line[2]."</td>";
				echo "<td align=center width =320>".$line[3]."</td>";
				echo "</tr>";
				$k++;
			}		
			fclose($fp); 
		?>
			
	   </table>
		
		
	</div>
	
	
	
	
	<div class="clear"></div>
</div>
<?php 	
    $path=Router::url(array('controller' => '/', 'action' =>''), true);
    $cuser=$session->read('User');
?>
<script>
$(document).ready(function(){
	$("#updata").live('click',function(){
			$(".load").css("display","block");
			$("#loadmsg").show();			
			$("#allupdatalog").hide();	
			getprogress(1);
		})
	$("#showlog").click(function(){
		$(".load").css("display","none");
		$("#loadmsg").hide();	
		$("#allupdatalog").toggle();
		})

		
})


//使用ajax 异步获取数据，以便在前台显示进程
function getprogress(step){
	var _self = arguments;
	$.ajax({
		url:"<?php echo  $path;?>notices/updatedo/"+step,
		async:true,//necessary
		success:function(data){

			$("#step"+step).show();	
			//$("<div class='load' >"+data+"</div>").appendTo("#loadmsg");
			if(step < 6){
				_self.callee(step+1);
			}else{
				window.location.reload(true);
				}
			
		}
	});
	
}

</script>